﻿using Microsoft.Office.Interop.Excel;
using Microsoft.Win32;
using MiniExcelLibs;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using PanhuaWin.工厂;
using PanhuaWin.系统管理;
using PanhuaWin.通用;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Forms;
using DataTable = System.Data.DataTable;

namespace PanhuaWin.车间.酸洗
{
    public partial class Form酸洗报工维护 : UIPage

    {


        string 工厂guid1;
        string 部门编号 = "";
        string 部门名称 = "";
        string FormGuid;
        int 开始行;
        int 结束行;
        string 部门guid;
        string tempguid;
        string 酸洗原卷guid;
        decimal 卷的总重量;
        string FormWorkType = "酸连轧";
        public Form酸洗报工维护()
        {
            InitializeComponent();
        }


        private void Form酸洗报工维护_Resize(object sender, EventArgs e)
        {


        }

        private void Form酸洗报工维护_Load(object sender, EventArgs e)
        {
            tempguid = Guid.NewGuid().ToString();
            this.uiTextBox工厂名称.Text = pub.全局工厂名称;
            this.uiDatePicker报工日期.Value = DateTime.Today.AddHours(-8);
            pub.ListMaterial(pub.全局工厂编号, FormWorkType, this.uiComboBox新材质);
            pub.ListRank(pub.全局工厂编号, this.uiComboBox质量等级);
            pub.ListRankAll(pub.全局工厂编号, this.uiComboBox查询等级);
            pub.ListWorkType(pub.全局工厂编号, FormWorkType, this.uiComboBox去向);
            pub.ListWorkTypeAll(pub.全局工厂编号, FormWorkType, this.uiComboBox查询去向);
            pub.ListQualityInfo(pub.全局工厂编号, FormWorkType, this.uiComboBox质量信息);
            pub.ListWorkLine(pub.全局工厂编号, FormWorkType, this.uiComboBox产线);
            pub.List品名(this.uiComboBox品名, FormWorkType, this.uiComboBox质量等级.SelectedText);
            pub.ListQualityStandard(FormWorkType, this.uiComboBox执行标准);
            pub.ListDayShift(pub.全局工厂编号, this.uiComboBoxDayShift);
            pub.ListWareHouse(this.uiComboBox仓库, pub.全局工厂guid);

            this.uiDatePicker1.Value = DateTime.Today;
            this.uiDatePicker2.Value = DateTime.Today;

            pub.ListWorkLineAll(pub.全局工厂编号, FormWorkType, this.uiComboBox查询产线);
            pub.ListWorkTeamAll(pub.全局工厂编号, this.uiComboBox产线.SelectedValue.ToString(), this.uiComboBox查询班组);
            清理自己mac的Temp_酸洗报工原卷占用();

            string 当前班组 = pub.Get员工所属班组(pub.sys_user.UserTrueName);
            if (当前班组 == "")
            {
                pub.ListWorkTeam(pub.全局工厂编号, this.uiComboBox产线.SelectedValue.ToString(), this.uiComboBoxWorkTeam);
            }
            else
            {
                this.uiComboBoxWorkTeam.Items.Add(当前班组);
                this.uiComboBoxWorkTeam.SelectedIndex = 0;
            }

            uiComboBox包装.Items.Add("精包");
            uiComboBox包装.Items.Add("简包");
            uiComboBox包装.Items.Add("普包");
            uiComboBox包装.Items.Add("裸包");
            uiComboBox包装.Items.Add("无");

        }

        private void 清理自己mac的Temp_酸洗报工原卷占用()
        {
            string sql;
            sql = "delete Temp_酸洗报工原卷占用 where mac='" + pub.getMac() + "' ";
            pub.ExecuteSql(pub.ConnectionString, sql, "清理自己mac的Temp_酸洗报工原卷占用,Temp_酸洗报工原卷占用");
        }
        private void uiButton选择已发未完工_Click(object sender, EventArgs e)
        {
            //CleallAll();
            //Form已发未完工卷 form已发未完工卷 = new Form已发未完工卷();
            //form已发未完工卷.工厂编号 = pub.全局工厂编号;
            //删除自己的tempguid的数据(tempguid);  //Temp_酸洗报工原卷占用
            //if (form已发未完工卷.ShowDialog(this) == DialogResult.OK)
            //{
            //    this.uiTextBox原料卷号.Text = form已发未完工卷.卷信息.VolumeCodeNew;
            //    酸洗原卷guid = pub.Get酸洗报工guid(this.uiTextBox原料卷号.Text);    //一个卷生成一个guid
            //    if (酸洗原卷guid == "")
            //    {
            //        MessageBox.Show("投入卷号选择有问题，请联系一下系统管理员处理: " + this.uiTextBox原料卷号.Text, "提示", MessageBoxButtons.OK);
            //        return;
            //    }
            //    this.uiTextBox产出卷号.Text = pub.去掉前缀(this.uiTextBox原料卷号.Text);//不含前缀，不含后面的串号


            //    uiTextBox规格型号1.Text = form已发未完工卷.卷信息.OriginalSize;
            //    string 厚度 = "";
            //    string 宽度 = "";
            //    string 虚拟值 = "";
            //    pub.FromSize(uiTextBox规格型号1.Text, out 厚度, out 宽度, out 虚拟值);
            //    this.uiTextBox厚度1.Text = 厚度;
            //    this.uiTextBox宽度1.Text = 宽度;

            //    this.uiTextBox新厚度.Text = 厚度;
            //    this.uiTextBox新宽度.Text = 宽度;
            //    this.uiTextBox产地1.Text = form已发未完工卷.卷信息.Address;
            //    this.uiTextBox卷重量1.Text =(pub.Todouble (form已发未完工卷.卷信息.Weight)*1000).ToString();
            //    this.uiTextBox新重量.Text = this.uiTextBox卷重量1.Text;
            //    this.uiTextBox材质1.Text = form已发未完工卷.卷信息.Material;
            //    this.uiComboBox新材质.Text = this.uiTextBox材质1.Text;
            //    this.uiTextBox计量单位1.Text = "Kg";
            //    this.uiComboBox去向.SelectedValue = form已发未完工卷.卷信息.NextWorkType;

            //    ListOutput(this.uiTextBox原料卷号.Text);
            //    塞入自己的tempguid的数据(tempguid, this.uiTextBox原料卷号.Text);
            //}
            //else
            //{
            //    酸洗原卷guid = "";
            //    删除自己的tempguid的数据(tempguid);  //Temp_酸洗报工原卷占用
            //}



        }

        private void 塞入自己的tempguid的数据(string tempguid, string volumeCodeNew)
        {
            string sql;
            sql = "insert into Temp_酸洗报工原卷占用(guid, OriginalVolumeNew, MAC, 时间 ) values('" + tempguid + "','" + volumeCodeNew + "','" + pub.getMac() + "' ,getdate()) ";
            pub.ExecuteSql(pub.ConnectionString, sql, "删除自己的tempguid的数据,Temp_酸洗报工原卷占用");
        }

        private void 删除自己的tempguid的数据(string tempguid)
        {
            string sql;
            //sql = "delete Temp_酸洗报工原卷占用 where guid='" + tempguid + "' ";
            sql = "delete Temp_酸洗报工原卷占用 where mac='" + pub.getMac() + "' ";
            pub.ExecuteSql(pub.ConnectionString, sql, "删除自己的tempguid的数据,Temp_酸洗报工原卷占用");
        }


        private void CleallAll()
        {
            this.uiDataGridView产出.DataSource = null;
            this.uiDataGridView产出.Refresh();
            this.uiTextBox产地1.Text = "";
            //this.uiCheckBox拆成多卷.Checked = false;
            this.numericUpDown1.Value = 1;
            uiTextBox原料卷号.Text = "";
            this.uiTextBox产出卷号.Text = "";
            酸洗原卷guid = "";
            删除自己的tempguid的数据(tempguid);


            uiTextBox规格型号1.Text = "";
            string 厚度 = "";
            string 宽度 = "";
            string 虚拟值 = "";

            this.uiTextBox厚度1.Text = 厚度;
            this.uiTextBox宽度1.Text = 宽度;

            this.uiTextBox新厚度.Text = 厚度;
            this.uiTextBox新宽度.Text = 宽度;
            this.uiTextBox产地1.Text = "";
            this.uiTextBox卷重量1.Text = "";
            this.uiTextBox材质1.Text = "";
            this.uiTextBox计量单位1.Text = "Kg";


            uiTextBox新重量.Text = "";
            uiTextBox新规格.Text = "";
            uiTextBox新重量.Text = "";

            tempguid = Guid.NewGuid().ToString();

            清理自己mac的Temp_酸洗报工原卷占用();

        }







        private void uiComboBox产线_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (this.uiComboBox产线.SelectedValue.ToString() != "")
            //{
            //    pub.ListWorkType(pub.全局工厂编号, FormWorkType, this.uiComboBox去向);
            //}
        }

        private void uiTextBox新厚度_TextChanged(object sender, EventArgs e)
        {
            SetSize();
        }

        private void uiTextBox新宽度_TextChanged(object sender, EventArgs e)
        {
            SetSize();
        }
        private void SetSize()
        {
            this.uiTextBox新规格.Text = pub.Todecimal(this.uiTextBox新厚度.Text, 3) + "*" + pub.Todecimal(this.uiTextBox新宽度.Text).ToString() + "*C";
        }

        private void uiCheckBox拆成多卷_CheckedChanged(object sender, EventArgs e)
        {
            if (this.uiCheckBox拆成多卷.Checked)
            {
                this.numericUpDown1.Visible = true;
            }
            else
            {
                this.numericUpDown1.Visible = false;
            }
        }

        private void uiButton添加产出卷_Click(object sender, EventArgs e)
        {

            if (pub.Todecimal(this.uiTextBox卷重量1.Text) < 卷的总重量 + pub.Todecimal(this.uiTextBox新重量.Text))
            {
                MessageBox.Show("产出卷的重量超过了投入卷重量,不能单卷报工。", "提示", MessageBoxButtons.OK);
                return;
            }
            if (this.uiCheckBox拆成多卷.Checked == false)
            {
                //单卷
                //已经存在的就不能再次点击添加了
                this.uiTextBox原料卷号.Text = "PHR" + this.uiTextBox原料卷号.Text.Replace("PHR", "");
                if (!pub.Is酸洗报工原始卷被关闭(this.uiTextBox原料卷号.Text))
                {
                    string sql;
                    List<Bus_PicklingOutput> bus_picklingoutputs = pub.Get酸洗产出卷信息All(this.uiTextBox原料卷号.Text);
                    if (bus_picklingoutputs != null)
                    {
                        MessageBox.Show("这个卷已经有产出卷了,不能单卷报工。", "提示", MessageBoxButtons.OK);
                        return;
                    }
                    //if (MessageBox.Show("这卷不再分拆会自动关闭，是否确认?", "询问", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    //{
                    单卷报工();
                    //}
                }
                else
                {
                    MessageBox.Show("这个卷已经被关闭了，不能再次报工了，如需要再次报工，请联系管理员处理。", "提示", MessageBoxButtons.OK);
                    return;
                }

            }
            else
            {
                //多卷
                //已经存在的就不能再次点击添加了
                if (!pub.Is酸洗报工原始卷被关闭(this.uiTextBox原料卷号.Text))
                {
                    List<Bus_PicklingOutput> bus_picklingoutputs = pub.Get酸洗产出卷信息All(this.uiTextBox原料卷号.Text);
                    if (bus_picklingoutputs != null)
                    {
                        bool s = false;
                        foreach (Bus_PicklingOutput bus_PicklingOutput in bus_picklingoutputs)
                        {
                            if (this.uiTextBox原料卷号.Text.Replace("PHR", "") == bus_PicklingOutput.OutputVolumeNew.Replace("PHS", ""))
                            {
                                s = true;
                            }
                        }
                        if (s)
                        {
                            MessageBox.Show("这个卷已经有产出单卷了,不能多卷报工。", "提示", MessageBoxButtons.OK);
                            return;
                        }

                    }
                    多卷报工();
                }
                else
                {
                    MessageBox.Show("这个卷已经被关闭了，不能再次报工了，如需要强制报工，请联系管理员处理。", "提示", MessageBoxButtons.OK);
                    return;
                }

            }
        }

        private void 多卷报工()
        {
            if (酸洗原卷guid == "" || this.uiTextBox原料卷号.Text == "")
            {
                MessageBox.Show("没有选择投入卷号", "提示", MessageBoxButtons.OK);
                return;
            }
            string sql;
            //在酸洗卷分卷时补0，比如01,02
            string 新卷号 = this.uiTextBox前缀.Text + this.uiTextBox产出卷号.Text + this.numericUpDown1.Value.ToString().PadLeft(2, '0');

            Bus_PicklingOutput bus_picklingoutput = new Bus_PicklingOutput();
            bus_picklingoutput.Creator = pub.sys_user.UserName;
            bus_picklingoutput.OutputDate = this.uiDatePicker报工日期.Value;
            if (this.uiComboBox去向.SelectedText == "")
            {
                MessageBox.Show("去向不能为空", "提示", MessageBoxButtons.OK);
                return;

            }
            if (pub.Get酸洗产出卷信息(新卷号) != null)
            {
                MessageBox.Show("产出卷号已经存在了，不能添加", "提示", MessageBoxButtons.OK);
                return;
            }
            bus_picklingoutput.OutputNext = this.uiComboBox去向.SelectedText;
            bus_picklingoutput.WorkLineName = this.uiComboBox产线.SelectedText;
            if (bus_picklingoutput.WorkLineName == "")
            {
                MessageBox.Show("产线为空，不能添加", "提示", MessageBoxButtons.OK);
                return;
            }
            bus_picklingoutput.WorkLineCode = this.uiComboBox产线.SelectedValue.ToString();

            bus_picklingoutput.DayShiftCode = this.uiComboBoxDayShift.SelectedValue.ToString();
            bus_picklingoutput.DayShiftName = this.uiComboBoxDayShift.SelectedText;

            bus_picklingoutput.WorkTeamCode = this.uiComboBoxWorkTeam.SelectedText;
            bus_picklingoutput.WorkTeamName = this.uiComboBoxWorkTeam.SelectedText;
            if (bus_picklingoutput.WorkTeamCode == "")
            {
                MessageBox.Show("班组为空，不能添加", "提示", MessageBoxButtons.OK);
                return;
            }
            Dic_Depart dic_Depart = pub.GetDepartByWorkLine(this.uiComboBox产线.SelectedText);
            if (bus_picklingoutput.DepartCode == "")
            {
                MessageBox.Show("部门为空，不能添加", "提示", MessageBoxButtons.OK);
                return;
            }

            bus_picklingoutput.guid = Guid.Parse(酸洗原卷guid);
            bus_picklingoutput.OutputGuid = Guid.NewGuid();
            bus_picklingoutput.OutputMaterial = this.uiComboBox新材质.SelectedText;
            bus_picklingoutput.OutputQualityGrade = this.uiComboBox质量等级.SelectedText;
            bus_picklingoutput.OutputQualityInformation = this.uiComboBox质量信息.Text.Trim().Replace("--", "");
            pub.UpdateQualityInformation(pub.全局工厂编号, FormWorkType, bus_picklingoutput.OutputQualityInformation);
            if (!pub.IsRightSize(this.uiTextBox新规格.Text))
            {
                MessageBox.Show("规格有问题，不能添加", "提示", MessageBoxButtons.OK);
                return;
            }
            bus_picklingoutput.OutputSize = this.uiTextBox新规格.Text;
            bus_picklingoutput.OutputThick = pub.Todecimal(uiTextBox新厚度.Text);
            bus_picklingoutput.OutputWidth = uiTextBox新宽度.Text;
            bus_picklingoutput.OutputWeight = pub.Todecimal(uiTextBox新重量.Text);
            if (bus_picklingoutput.OutputWeight == 0)
            {
                MessageBox.Show("重量为0，不能添加", "提示", MessageBoxButtons.OK);
                return;
            }
            bus_picklingoutput.Customer = this.uiTextBox客户.Text;
            bus_picklingoutput.OutputAddress = this.uiTextBox产地1.Text;
            if (this.uiComboBox品名.Visible == true)
            {
                bus_picklingoutput.InventoryName = uiComboBox品名.SelectedText;
                bus_picklingoutput.InventoryCode = pub.GetInventoryCode(bus_picklingoutput.InventoryName, bus_picklingoutput.OutputSize, bus_picklingoutput.OutputMaterial);
                if (bus_picklingoutput.InventoryCode == "")
                {
                    MessageBox.Show("这个卷没有对应的NC存货编号", "提示", MessageBoxButtons.OK);
                }
            }
            sql = " insert into Bus_PicklingOutput(OutputGuid, outputdate,guid, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight, ";
            sql += " OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, ";
            sql += " WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator,";
            sql += " CreateDate,OutputAddress,InventoryCode, InventoryName,Customer )";
            sql += " values(newid(),'" + bus_picklingoutput.OutputDate + "','" + 酸洗原卷guid + "','" + this.uiTextBox原料卷号.Text.Trim().Replace("--", "") + "','" + this.numericUpDown1.Value.ToString() + "','" + 新卷号 + "','" + bus_picklingoutput.OutputSize + "','" + bus_picklingoutput.OutputThick + "','" + bus_picklingoutput.OutputWidth + "',";
            sql += " '" + bus_picklingoutput.OutputMaterial + "','" + bus_picklingoutput.OutputWeight + "','" + bus_picklingoutput.OutputQualityGrade + "','" + bus_picklingoutput.OutputQualityInformation + "',";
            sql += "  '','" + bus_picklingoutput.OutputNext + "',0,'" + bus_picklingoutput.DepartCode + "','" + bus_picklingoutput.DepartName + "',";
            sql += " '" + bus_picklingoutput.WorkLineCode + "','" + bus_picklingoutput.WorkLineName + "','" + bus_picklingoutput.WorkTeamCode + "','" + bus_picklingoutput.WorkTeamName + "',";
            sql += " '" + bus_picklingoutput.DayShiftCode + "','" + bus_picklingoutput.DayShiftName + "','" + pub.sys_user.User_Id + "','" + pub.sys_user.UserTrueName + "',";
            sql += " getdate(),'" + bus_picklingoutput.OutputAddress + "','" + bus_picklingoutput.InventoryCode + "','" + bus_picklingoutput.InventoryName + "','" + bus_picklingoutput.Customer + "') ";
            if (pub.ExecuteSql(pub.ConnectionString, sql, "多卷酸洗报工塞入Bus_PicklingOutput") > 0)
            {
                MessageBox.Show("多卷酸洗报工成功", "提示", MessageBoxButtons.OK);
                //不用自动关闭
                //sql = "update Bus_PicklingOriginal set IsClosed='Y' , ColseUserId='" + pub.sys_user.User_Id + "',ColseUserName='" + pub.sys_user.UserTrueName + "',CloseDate=getdate() where guid='" + 酸洗原卷guid + "'";
                //pub.ExecuteSql(pub.ConnectionString, sql, "单卷酸洗报工成功，自动关闭原卷的状态");
                //显示卷信息到表格上
                ListOutput(this.uiTextBox原料卷号.Text);
                this.numericUpDown1.Value = this.numericUpDown1.Value + 1;
                return;
            }
        }

        private void 单卷报工()
        {
            if (酸洗原卷guid == "" || this.uiTextBox原料卷号.Text == "")
            {
                MessageBox.Show("没有选择投入卷号", "提示", MessageBoxButtons.OK);
                return;
            }
            string sql;
            string 新卷号 = this.uiTextBox前缀.Text + this.uiTextBox产出卷号.Text;
            Bus_PicklingOutput bus_picklingoutput = new Bus_PicklingOutput();
            bus_picklingoutput.Creator = pub.sys_user.UserName;
            bus_picklingoutput.OutputDate = this.uiDatePicker报工日期.Value;
            if (this.uiComboBox去向.SelectedText == "")
            {
                MessageBox.Show("去向不能为空", "提示", MessageBoxButtons.OK);
                return;

            }
            bus_picklingoutput.OutputNext = this.uiComboBox去向.SelectedText;
            bus_picklingoutput.WorkLineName = this.uiComboBox产线.SelectedText;
            if (bus_picklingoutput.WorkLineName == "")
            {
                MessageBox.Show("产线为空，不能添加", "提示", MessageBoxButtons.OK);
                return;
            }
            bus_picklingoutput.WorkLineCode = this.uiComboBox产线.SelectedValue.ToString();

            bus_picklingoutput.DayShiftCode = this.uiComboBoxDayShift.SelectedValue.ToString();
            bus_picklingoutput.DayShiftName = this.uiComboBoxDayShift.SelectedText;

            bus_picklingoutput.WorkTeamCode = this.uiComboBoxWorkTeam.SelectedText;
            bus_picklingoutput.WorkTeamName = this.uiComboBoxWorkTeam.SelectedText;
            if (bus_picklingoutput.WorkTeamCode == "")
            {
                MessageBox.Show("班组为空，不能添加", "提示", MessageBoxButtons.OK);
                return;
            }


            //if (bus_picklingoutput.DepartCode == "")
            //{
            //    MessageBox.Show("部门为空，不能添加", "提示", MessageBoxButtons.OK);
            //    return;

            //}

            bus_picklingoutput.guid = Guid.Parse(酸洗原卷guid);
            bus_picklingoutput.OutputGuid = Guid.NewGuid();
            bus_picklingoutput.OutputMaterial = this.uiComboBox新材质.SelectedText;
            bus_picklingoutput.OutputQualityGrade = this.uiComboBox质量等级.SelectedText;
            bus_picklingoutput.OutputQualityInformation = this.uiComboBox质量信息.Text.Trim().Replace("--", "");
            pub.UpdateQualityInformation(pub.全局工厂编号, FormWorkType, bus_picklingoutput.OutputQualityInformation);
            if (!pub.IsRightSize(this.uiTextBox新规格.Text))
            {
                MessageBox.Show("规格有问题，不能添加", "提示", MessageBoxButtons.OK);
                return;
            }
            bus_picklingoutput.OutputSize = this.uiTextBox新规格.Text;
            bus_picklingoutput.OutputThick = pub.Todecimal(uiTextBox新厚度.Text);
            bus_picklingoutput.OutputWidth = uiTextBox新宽度.Text;
            bus_picklingoutput.OutputWeight = pub.Todecimal(uiTextBox新重量.Text);
            if (bus_picklingoutput.OutputWeight == 0)
            {
                MessageBox.Show("重量为0，不能添加", "提示", MessageBoxButtons.OK);
                return;
            }
            bus_picklingoutput.Customer = this.uiTextBox客户.Text.Trim();
            bus_picklingoutput.OutputAddress = this.uiTextBox产地1.Text;
            if (this.uiComboBox品名.Visible == true)
            {
                bus_picklingoutput.InventoryName = uiComboBox品名.SelectedText;
                bus_picklingoutput.InventoryCode = pub.GetInventoryCode(bus_picklingoutput.InventoryName, bus_picklingoutput.OutputSize, bus_picklingoutput.OutputMaterial);
                if (bus_picklingoutput.InventoryCode == "")
                {
                    MessageBox.Show("这个卷没有对应的NC存货编号", "提示", MessageBoxButtons.OK);
                }
            }


            sql = " insert into Bus_PicklingOutput(OutputGuid, outputdate,guid, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight, ";
            sql += " OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, ";
            sql += " WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator,";
            sql += " CreateDate,OutputAddress,InventoryCode, InventoryName,customer )";
            sql += " values(newid(),'" + bus_picklingoutput.OutputDate + "','" + 酸洗原卷guid + "','" + this.uiTextBox原料卷号.Text.Trim().Replace("--", "") + "','" + this.numericUpDown1.Value.ToString() + "','" + 新卷号 + "','" + bus_picklingoutput.OutputSize + "','" + bus_picklingoutput.OutputThick + "','" + bus_picklingoutput.OutputWidth + "',";
            sql += " '" + bus_picklingoutput.OutputMaterial + "','" + bus_picklingoutput.OutputWeight + "','" + bus_picklingoutput.OutputQualityGrade + "','" + bus_picklingoutput.OutputQualityInformation + "',";
            sql += "  '','" + bus_picklingoutput.OutputNext + "',0,'" + bus_picklingoutput.DepartCode + "','" + bus_picklingoutput.DepartName + "',";
            sql += " '" + bus_picklingoutput.WorkLineCode + "','" + bus_picklingoutput.WorkLineName + "','" + bus_picklingoutput.WorkTeamCode + "','" + bus_picklingoutput.WorkTeamName + "',";
            sql += " '" + bus_picklingoutput.DayShiftCode + "','" + bus_picklingoutput.DayShiftName + "','" + pub.sys_user.User_Id + "','" + pub.sys_user.UserTrueName + "',";
            sql += " getdate(),'" + bus_picklingoutput.OutputAddress + "','" + bus_picklingoutput.InventoryCode + "','" + bus_picklingoutput.InventoryName + "','" + bus_picklingoutput.Customer + "') ";
            if (pub.ExecuteSql(pub.ConnectionString, sql, "单卷酸洗报工塞入Bus_PicklingOutput") > 0)
            {
                MessageBox.Show("单卷酸洗报工成功", "提示", MessageBoxButtons.OK);
                //sql = "update Bus_PicklingOriginal set IsClosed='Y' , ColseUserId='" + pub.sys_user.User_Id + "',ColseUserName='" + pub.sys_user.UserTrueName + "',CloseDate=getdate() where guid='" + 酸洗原卷guid + "'";
                //pub.ExecuteSql(pub.ConnectionString, sql, "单卷酸洗报工成功，自动关闭原卷的状态");
                //显示卷信息到表格上
                ListOutput(this.uiTextBox原料卷号.Text);
                return;
            }


        }

        private void ListOutput(string 投入卷号)
        {
            卷的总重量 = 0;
            string 查询投入卷号 = "PHR" + 投入卷号.Replace("PHR", "");  //只查卷号的7位纯数字
            string sql;
            sql = "SELECT   OutputGuid,outputdate 报工日期, guid, Row, OutputVolumeNew 新卷号, OutputSize 新规格, OutputThick 新厚度, OutputWidth 新宽度,";
            sql += " OutputMaterial 新材质, OutputWeight 新重量, OutputQualityGrade 质量等级, OutputQualityInformation 质量信息, ";
            sql += " OutputEndStatus 后续状态, OutputNext 去向,InventoryCode 存货编号,InventoryName 品名,";
            sql += " PrintTimes 打印次数, DepartCode 部门编号, DepartName 生产部门,  WorkLineCode 产线编号, WorkLineName 产线,";
            sql += "  WorkTeamCode 班组编号, WorkTeamName 班组, DayShiftCode 班别编号, DayShiftName 班别, CreateID, Creator 填报人,";
            sql += " CreateDate 填报时间, ModifyID, Modifier, ModifyDate,Customer 客户  ";
            sql += " FROM      Bus_PicklingOutput where VolumeCodeNew='" + 查询投入卷号 + "' order by OutputVolumeNew ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null)
            {
                uiDataGridView产出.AutoGenerateColumns = false;
                this.uiDataGridView产出.DataSource = tb;
                this.uiDataGridView产出.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                this.uiDataGridView产出.Refresh();
                for (int i=0;i<this.uiDataGridView产出.Rows.Count;i++)
                {
                    if (this.uiDataGridView产出.Rows[i].Cells["C质量等级"].Value.ToString()=="B")
                    {
                        this.uiDataGridView产出.Rows[i].Cells["C质量等级"].Style.BackColor = Color.FromArgb(255, 255, 128);
                    }
                    else if (this.uiDataGridView产出.Rows[i].Cells["C质量等级"].Value.ToString() == "S")
                    {
                        this.uiDataGridView产出.Rows[i].Cells["C质量等级"].Style.BackColor = Color.FromArgb(255, 0, 0);
                    }
                }
                //产出卷必须连号,不连号不行。

                if (tb.Rows.Count > 0)
                {
                    if (tb.Rows.Count == 1)
                    {
                        卷的总重量 = pub.Todecimal(tb.Rows[0]["新重量"].ToString());
                      }
                    else
                    {
                         for (int i = 0; i < tb.Rows.Count; i++)
                        {
                            卷的总重量 += pub.Todecimal(tb.Rows[i]["新重量"].ToString());
                            //if (this.uiTextBox前缀.Text + uiTextBox产出卷号.Text + (i + 1).ToString().PadLeft(2, '0') != tb.Rows[i]["新卷号"].ToString())
                            //{
                            //    MessageBox.Show("产出的卷号不连号请检查", "提示", MessageBoxButtons.OK);
                            //}
                        }
                    }

                }
            }


            //显示是否关闭了。
            sql = "select IsClosed from Bus_PicklingOriginal where OriginalVolumeNew='" + 投入卷号 + "'  ";
            DataTable tb2 = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb2 != null)
            {
                if (tb2.Rows.Count > 0)
                {
                    if (tb2.Rows[0]["IsClosed"].ToString() == "Y")
                    {
                        this.uiLabelIsClosed.Text = "已关闭";
                    }
                    else
                    {
                        this.uiLabelIsClosed.Text = "未关闭";
                    }
                }
            }

        }

        private void Form酸洗报工维护_FormClosed(object sender, FormClosedEventArgs e)
        {
            删除自己的tempguid的数据(tempguid);
        }

        private void uiDataGridView产出_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.uiDataGridView产出.Rows.Count > 0)
            {
                 
                if (this.uiDataGridView产出.Columns[e.ColumnIndex].Name == "C删除")
                {
                    if (!pub.Is酸洗报工原始卷被关闭(this.uiTextBox原料卷号.Text))
                    {
                        string 酸洗产出卷号 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C新卷号"].Value.ToString();
                        string 后续状态 = pub.Get酸洗产出卷的后续状态(酸洗产出卷号);
                        if (后续状态 != "未使用")
                        {
                            MessageBox.Show("这个卷状态:" + 后续状态, "提示", MessageBoxButtons.OK);
                            //显示卷信息到表格上
                            // this.uiDataGridView产出.Rows[e.RowIndex].Cells["C后续状态"].Value = 后续状态;
                            ListOutput(this.uiTextBox原料卷号.Text);
                            return;
                        }
                        else
                        {   //本人才能删除
                            string 填报人 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C填报人"].Value.ToString();
                            if (填报人 != pub.sys_user.UserTrueName)
                            {
                                MessageBox.Show("您不可以删除其他人员填报的数据", "提示", MessageBoxButtons.OK);
                                return;
                            }
                            if (MessageBox.Show("你要删除这个产出卷么?", "询问", MessageBoxButtons.OKCancel) == DialogResult.OK)
                            {
                                //检查是否打印打标签了
                                if (pub.产出卷是否打印入库(酸洗产出卷号))
                                {
                                    MessageBox.Show("【" + 酸洗产出卷号 + "】已经打印大标签入库，无法删除");
                                    return;
                                }

                                string sql = "delete Bus_PicklingOutput where OutputVolumeNew='" + 酸洗产出卷号 + "';";
                                sql += "delete from Bus_LablePrint where 生产批号 = '" + 酸洗产出卷号 + "';";
                                pub.ExecuteSql(pub.ConnectionString, sql, "删除产出的酸洗卷");
                                //原卷的状态还原
                                sql = "update Bus_PicklingOriginal set IsClosed='N' , ColseUserId=NULL,ColseUserName=NULL,CloseDate=NULL where guid='" + 酸洗原卷guid + "'";
                                pub.ExecuteSql(pub.ConnectionString, sql, "单卷酸洗报工取消成功，自动开启原卷的状态");

                                ListOutput(this.uiTextBox原料卷号.Text);
                            }

                        }
                    }
                    else
                    {
                        MessageBox.Show("已经关闭的投入卷不能删除产出卷信息", "提示", MessageBoxButtons.OK);
                        ListOutput(this.uiTextBox原料卷号.Text);
                        return;
                    }
                }
                else if (this.uiDataGridView产出.Columns[e.ColumnIndex].Name == "C打印小标签" && this.uiDataGridView产出.Rows[e.RowIndex].Cells["C去向"].Value.ToString() == "下线入库")
                {
                    Form小标签 form小标签 = new Form小标签();
                    form小标签.生产批号 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C新卷号"].Value.ToString();
                    form小标签.规格 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C新规格"].Value.ToString();
                    form小标签.钢号 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C新材质"].Value.ToString();
                    form小标签.等级 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C质量等级"].Value.ToString();
                    form小标签.净重 = Math.Round(pub.Todecimal(this.uiDataGridView产出.Rows[e.RowIndex].Cells["C新重量"].Value.ToString()), 0).ToString();
                    form小标签.工厂编号 = pub.全局工厂编号;
                    form小标签.来源种类 = "酸洗小标签";
                    form小标签.存货编号 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C存货编号"].Value.ToString();
                    form小标签.品名 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C品名"].Value.ToString();
                    form小标签.表面处理 = "";
                    form小标签.表面状态 = "";
                    form小标签.执行标准 = "";
                    form小标签.长度 = "";
                    form小标签.班组 = this.uiComboBoxWorkTeam.SelectedText;
                    form小标签.锌层 = this.uiTextBox锌层.Text;
                    form小标签.颜色 = this.uiTextBox颜色.Text;
                    form小标签.包装 = this.uiComboBox包装.SelectedText ;
                    form小标签.仓库 = this.uiComboBox仓库.SelectedValue.ToString();  ///使用的是编号
                    form小标签.客户 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C客户"].Value.ToString();
                    form小标签.生产日期 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C报工日期"].Value.ToString();
                    //form小标签.ShowDialog(this);
                    form小标签.打印();


                }
            }
        }

        private void uiButton关闭_Click(object sender, EventArgs e)
        {
            //检查卷号是否存在
            if (this.uiTextBox原料卷号.Text != "")
            {



                string sql;
                //产出卷必须连号
                sql = "SELECT   OutputGuid, guid, Row, OutputVolumeNew 新卷号, OutputSize 新规格, OutputThick 新厚度, OutputWidth 新宽度, OutputMaterial 新材质, OutputWeight 新重量, OutputQualityGrade 质量等级, OutputQualityInformation 质量信息, OutputEndStatus 后续状态, OutputNext 去向,";
                sql += " PrintTimes 打印次数, DepartCode 部门编号, DepartName 生产部门,  WorkLineCode 产线编号, WorkLineName 产线, WorkTeamCode 班组编号, WorkTeamName 班组, DayShiftCode 班别编号, DayShiftName 班别, CreateID, Creator 填报人,  CreateDate 填报时间, ModifyID, Modifier, ModifyDate ";
                sql += " FROM      Bus_PicklingOutput where guid='" + 酸洗原卷guid + "' order by OutputVolumeNew ";
                DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
                if (tb != null)
                {
                    uiDataGridView产出.AutoGenerateColumns = false;
                    this.uiDataGridView产出.DataSource = tb;
                    this.uiDataGridView产出.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                    this.uiDataGridView产出.Refresh();
                    //产出卷必须连号,不连号不行。
                    if (tb.Rows.Count > 0)
                    {
                        if (tb.Rows.Count == 1)
                        {
                            //只有一卷
                        }
                        else
                        {
                            for (int i = 0; i < tb.Rows.Count; i++)
                            {
                                if (this.uiTextBox前缀.Text + uiTextBox产出卷号.Text + (i + 1).ToString().PadLeft(2, '0') != tb.Rows[i]["新卷号"].ToString())
                                {
                                    MessageBox.Show("产出的卷号不连号请检查", "提示", MessageBoxButtons.OK);
                                    return;
                                }
                            }
                        }

                        if (MessageBox.Show("你要关闭这个投入卷么?", "询问", MessageBoxButtons.OKCancel) == DialogResult.OK)
                        {
                            sql = "update Bus_PicklingOriginal set IsClosed='Y' , ColseUserId='" + pub.sys_user.User_Id + "',ColseUserName='" + pub.sys_user.UserTrueName + "',CloseDate=getdate() where guid='" + 酸洗原卷guid + "'";
                            pub.ExecuteSql(pub.ConnectionString, sql, "酸洗手动关闭原卷的状态");
                            ListOutput(this.uiTextBox原料卷号.Text);
                        }
                    }




                }
            }
        }

        private void uiTextBox原料卷号_KeyPress(object sender, KeyPressEventArgs e)
        {

        }

        private void uiButton搜索已生产卷_Click(object sender, EventArgs e)
        {
            List已生产卷();
        }
        private void List已生产卷()
        {
            Form已发未完工卷 form已发未完工卷 = new Form已发未完工卷();
            form已发未完工卷.工厂编号 = pub.全局工厂编号;
            string 用来保存的原卷号 = "";
            酸洗原卷guid = pub.Get酸洗报工guid(this.uiTextBox原料卷号.Text,out 用来保存的原卷号);
            if (酸洗原卷guid == "")
            {
                MessageBox.Show("投入卷号选择有问题，请联系一下系统管理员处理: " + this.uiTextBox原料卷号.Text, "提示", MessageBoxButtons.OK);
                return;
            }
            this.uiTextBox原料卷号.Text = 用来保存的原卷号;
            Bus_StockOutVolume 出库卷信息 = new Bus_StockOutVolume();

            出库卷信息 = pub.Get酸洗出库卷信息(this.uiTextBox原料卷号.Text);
            if (出库卷信息 == null)
            {
                MessageBox.Show("投入卷号选择有问题，请联系一下系统管理员处理: " + this.uiTextBox原料卷号.Text, "提示", MessageBoxButtons.OK);
                return;
            }

            this.uiTextBox产出卷号.Text = pub.去掉前缀(this.uiTextBox原料卷号.Text);//不含前缀，不含后面的串号
            List<Bus_PlanPickling> bus_PlanPicklings = pub.Get酸洗计划组(this.uiTextBox原料卷号.Text);
            Bus_PlanPickling bus_PlanPickling = new Bus_PlanPickling();
            if (bus_PlanPicklings != null)
            {
                bus_PlanPickling = bus_PlanPicklings[0];
            }
            else
            {
                MessageBox.Show("投入卷: " + this.uiTextBox原料卷号.Text + "没有酸洗计划!", "提示", MessageBoxButtons.OK);
                return;
            }

            uiTextBox规格型号1.Text = 出库卷信息.Size;//原料的规格
            string 原料的厚度 = "";
            string 原料的宽度 = "";
            string 成品的厚度 = "";
            string 成品的宽度 = "";
            string 虚拟值 = "";
            pub.FromSize(uiTextBox规格型号1.Text, out 原料的厚度, out 原料的宽度, out 虚拟值);
            if (bus_PlanPickling.ProductSize!="")
            {
                pub.FromSize(bus_PlanPickling.ProductSize, out 成品的厚度, out 成品的宽度, out 虚拟值);
            }
            this.uiTextBox厚度1.Text = 原料的厚度;
            this.uiTextBox宽度1.Text = 原料的宽度;

            this.uiTextBox新厚度.Text = 原料的厚度;
            this.uiTextBox新宽度.Text = 成品的宽度;

            this.uiTextBox产地1.Text = bus_PlanPickling.Address;
            this.uiTextBox客户.Text = bus_PlanPickling.Customer;
            this.uiTextBox卷重量1.Text = (出库卷信息.Weight * 1000).ToString();

            this.uiTextBox新重量.Text = "";
            this.uiTextBox材质1.Text = 出库卷信息.Material;
            if (bus_PlanPickling.Material!="")
            {
                this.uiComboBox新材质.Text = bus_PlanPickling.Material;
            }
            else
            {
                //this.uiComboBox新材质.Text = 出库卷信息.Material;
            }
           
            this.uiTextBox计量单位1.Text = "Kg";
            if (出库卷信息.NextWorkType != null && 出库卷信息.NextWorkType != "")
            {
                this.uiComboBox去向.SelectedValue = 出库卷信息.NextWorkType;
            }
            ListOutput(this.uiTextBox原料卷号.Text);
            塞入自己的tempguid的数据(tempguid, this.uiTextBox原料卷号.Text);
        }
        private void uiButtonClearAll_Click(object sender, EventArgs e)
        {
            CleallAll();

        }
        private void uiComboBox去向_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.uiComboBox去向.SelectedText == "下线入库")
            {
                this.uiLabel品名.Visible = true;
                this.uiComboBox品名.Visible = true;
                this.uiLabel仓库.Visible = true;
                this.uiComboBox仓库.Visible = true;
                this.uiLabel包装.Visible = true;
                this.uiLabel锌层.Visible = true;
                this.uiTextBox锌层.Visible = true;
                this.uiLabel颜色.Visible = true;
                this.uiTextBox颜色.Visible = true;
            }
            else
            {
                this.uiLabel品名.Visible = false;
                this.uiComboBox品名.Visible = false;
                this.uiLabel仓库.Visible = false;
                this.uiComboBox仓库.Visible = false;
                this.uiLabel包装.Visible = false;
                this.uiLabel锌层.Visible = false;
                this.uiTextBox锌层.Visible = false;
                this.uiLabel颜色.Visible = false;
                this.uiTextBox颜色.Visible = false;
            }
        }

        private void uiComboBox质量等级_SelectedIndexChanged(object sender, EventArgs e)
        {
            pub.List品名(this.uiComboBox品名, FormWorkType, this.uiComboBox质量等级.SelectedText);
        }

        private void uiButton投入查询_Click(object sender, EventArgs e)
        {
            List待酸洗清单();
        }

        private void List待酸洗清单()
        {
            string sql;
            sql = @"SELECT row_number() over(order by  计划日期,卷号 ) 序号,   工厂编号, 仓库编号, 库位编号, 存货编号, 卷号, 轧制规格, 成品规格, 去向, 材质,产地, 计划日期, 产线编号, 产线名称, 规格型号, 
                重量, 备注,客户 FROM      View_已发未完工卷 where 1=1 ";
            sql += " and 工厂编号='" + pub.全局工厂编号 + "' ";
            if (this.uiTextBox查询材质.Text != "")
            {
                sql += " and 材质 ='" + this.uiTextBox查询材质.Text + "'";
            }
            if (this.uiTextBox查询规格型号.Text.Trim() != "")
            {
                sql += " and 规格型号 ='" + this.uiTextBox查询规格型号.Text.Trim().Replace("--", "") + "'";
            }

            if (this.uiTextBox查询卷号.Text.Trim() != "")
            {
                sql += " and 卷号 like '%" + this.uiTextBox查询卷号.Text.Trim().Replace("--", "") + "%'";
            }
            if (this.uiComboBox查询去向.SelectedText.Trim() != "全部" && this.uiComboBox查询去向.SelectedText.Trim() != "")
            {
                sql += " and 去向 ='" + this.uiComboBox查询去向.SelectedText.Trim().Replace("--", "") + "'";
            }

            if (this.uiTextBox查询成品规格.Text.Trim() != "")
            {
                sql += " and 成品规格 ='" + this.uiTextBox查询成品规格.Text.Trim().Replace("--", "") + "'";
            }
            if (this.uiTextBox查询客户.Text.Trim() != "")
            {
                sql += " and 客户 ='" + this.uiTextBox查询客户.Text.Trim().Replace("--", "") + "'";
            }
            // sql += " and 产线名称='"+ this.uiComboBox产线.SelectedText +"'";


            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {

                this.uiDataGridView可用.AutoGenerateColumns = false;
                this.uiDataGridView可用.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                this.uiDataGridView可用.DataSource = tb;
                this.uiDataGridView可用.Refresh();
            }
            else
            {
                //this.uiDataGridView已发未结束.AutoGenerateColumns = false;
                //this.uiDataGridView已发未结束.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                this.uiDataGridView可用.DataSource = null;
                this.uiDataGridView可用.Refresh();
                MessageBox.Show("没有已发料未结束的卷可以选择", "提示", MessageBoxButtons.OK);
                return;

            }
        }

        private void uiDataGridView可用_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            string 用来保存的原卷号 = "";
            if (e.RowIndex >= 0 && this.uiDataGridView可用.Columns[e.ColumnIndex].Name == "D选择")
            {
                this.uiTextBox原料卷号.Text = this.uiDataGridView可用.Rows[e.RowIndex].Cells["D卷号"].Value.ToString();
                酸洗原卷guid = pub.Get酸洗报工guid(this.uiTextBox原料卷号.Text,out  用来保存的原卷号);
                this.uiTextBox原料卷号.Text = 用来保存的原卷号;
                List已生产卷();
            }
        }

        private void uiButton查询_Click(object sender, EventArgs e)
        {
            DataTable tb = ListData();
            uiDataGridView1.AutoGenerateColumns = false;
            this.uiDataGridView1.DataSource = tb;
            this.uiDataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            this.uiDataGridView1.Refresh();
            for (int i = 0; i < this.uiDataGridView1.RowCount; i++)
            {
                if (this.uiDataGridView1.Rows[i].Cells["C产出等级"].Value.ToString() == "B")
                {
                    this.uiDataGridView1.Rows[i].Cells["C产出等级"].Style.BackColor = Color.FromArgb(255, 255, 128);
                }
                else if(this.uiDataGridView1.Rows[i].Cells["C产出等级"].Value.ToString() == "S")
                {
                    this.uiDataGridView1.Rows[i].Cells["C产出等级"].Style.BackColor = Color.FromArgb(255, 0, 0);
                }
            }
        }
        private DataTable ListData()
        {
            string sql;
            sql = "SELECT   row_number() over(order by 投入卷号) 序号, 投入卷号, 投入规格, 投入重量, 投入材质, 生产日期, 产出卷号, 产出规格, 产出材质, 产出重量, 产出等级, 去向, 产线名称, ";
            sql += " 班组名称, 班别,客户 FROM      View_酸洗投入产出明细表 ";
            sql += " where 1=1  and 生产日期 >='" + this.uiDatePicker1.Value.ToString() + "'";
            sql += " and 生产日期 < '" + this.uiDatePicker2.Value.AddDays(1) + "'";
            string sql2 = "select isnull(sum(投入重量),0) ,isnull(sum(产出重量),0)  FROM      View_酸洗投入产出明细表 ";
            sql2 += " where 1=1  and 生产日期 >='" + this.uiDatePicker1.Value.ToString() + "'";
            sql2 += " and 生产日期 < '" + this.uiDatePicker2.Value.AddDays(1) + "'";

            if (uiTextBox投入卷号包含.Text != "")
            {
                sql += " and 投入卷号 like '%" + this.uiTextBox投入卷号包含.Text + "%'";
                sql2 += " and 投入卷号 like '%" + this.uiTextBox投入卷号包含.Text + "%'";
            }
            if (uiTextBox产出卷号包含.Text != "")
            {
                sql += " and 产出卷号 like '%" + this.uiTextBox产出卷号包含.Text + "%'";
                sql2 += " and 产出卷号 like '%" + this.uiTextBox产出卷号包含.Text + "%'";
            }
            if (this.uiComboBox查询产线.SelectedText != "全部")
            {
                sql += " and 产线名称='" + this.uiComboBox查询产线.SelectedText + "' ";
                sql2 += " and 产线名称='" + this.uiComboBox查询产线.SelectedText + "' ";
            }
            if (this.uiComboBox查询班组.SelectedText != "全部")
            {
                sql += " and 班组名称='" + this.uiComboBox查询班组.SelectedText + "' ";
                sql2 += " and 班组名称='" + this.uiComboBox查询班组.SelectedText + "' ";
            }
            if (this.uiComboBox查询等级.SelectedText != "全部")
            {
                sql += " and 产出等级='" + this.uiComboBox查询等级.SelectedText + "' ";
                sql2 += " and 产出等级='" + this.uiComboBox查询等级.SelectedText + "' ";
            }
            sql += " order by 投入卷号 ";

            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            DataTable tb2 = pub.GetDataTable(pub.ConnectionString, sql2);
            if (tb2.Rows.Count >0)
            {
                this.uiTextBox投入重量合计.Text = tb2.Rows[0][0].ToString();
                this.uiTextBox产出重量合计.Text = pub.Todecimal(tb2.Rows[0][1].ToString(),3);
                decimal 总投入重量 = pub.Todecimal(this.uiTextBox投入重量合计.Text);
                decimal 总产出重量 = pub.Todecimal(this.uiTextBox产出重量合计.Text);

                if (总投入重量 > 0)
                {
                    this.uiTextBox产出率.Text = Math.Round((pub.Todecimal(总产出重量 / 总投入重量) * 100), 2).ToString();
                }
                else
                {
                    this.uiTextBox产出率.Text = "";
                }
            }
                this.uiTextBox卷数.Text =tb.Rows.Count .ToString();

            return tb;
        }

        private void uiButton导出_Click(object sender, EventArgs e)
        {
            string path;
            DataTable tb = ListData();
            saveFileDialog1.Filter = "Excel文件 (*.XLSX)|*.XLSX";
            if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                path = this.saveFileDialog1.FileName;
                if (!File.Exists(path))
                {
                    MiniExcel.SaveAs(path, tb, true, "sheet1", ExcelType.XLSX);
                }
                else
                {
                    MessageBox.Show("文件已经存在,请重试!", "提示", MessageBoxButtons.OK);
                    return;
                }

            }
        }

        private void uiDataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            开始行 = e.RowIndex;
        }

        private void uiDataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            decimal 总投入重量 = 0;
            decimal 投入重量 = 0;
            decimal 总产出重量 = 0;
         
            string guid = Guid.NewGuid().ToString();
            int 总卷数 = 0;
            结束行 = e.RowIndex;
            if (开始行 >= 0 && 结束行 > 0)
            {
                if (开始行 > 结束行)
                {
                    int k = 开始行;
                    开始行 = 结束行;
                    结束行 = k;
                }
                string sql = "delete Temp_投入汇总表 where guid='" + guid + "'";
                pub.ExecuteSql(pub.ConnectionString, sql, "delete Temp_投入汇总表 ");
                for (int i = 开始行; i <= 结束行; i++)
                {
                    投入重量 = pub.Todecimal(this.uiDataGridView1.Rows[i].Cells["C投入重量"].Value.ToString());
                    string 投入卷号 = this.uiDataGridView1.Rows[i].Cells["C投入卷号"].Value.ToString();
                    sql = " insert into Temp_投入汇总表 (guid, 卷号, 投入重量) ";
                    sql += " values('" + guid + "','" + 投入卷号 + "','" + 投入重量 + "')";
                    pub.ExecuteSql(pub.ConnectionString, sql, "insert into Temp_投入汇总表 ");

                    总产出重量 += pub.Todecimal(this.uiDataGridView1.Rows[i].Cells["C产出重量"].Value.ToString());
                    总卷数++;
                }
                sql = "select  isnull(  sum(t.投入重量),0)  from  (select distinct 卷号, 投入重量 from Temp_投入汇总表 where guid='" + guid + "' ) t ";
                DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
                if ( tb.Rows.Count >0)
                {
                    总投入重量 = pub.Todecimal(tb.Rows[0][0].ToString());
                }
                  else
                {
                    总投入重量 = 0;
                }
                sql = "delete Temp_投入汇总表 where guid='" + guid + "'";
                pub.ExecuteSql(pub.ConnectionString, sql, "delete Temp_投入汇总表 ");

                if (总投入重量 != 0)
                {
                    this.uiTextBox产出率.Text = Math.Round((pub.Todecimal(总产出重量 / 总投入重量) * 100), 2).ToString();
                }
                else
                {
                    this.uiTextBox产出率.Text = "";
                }
                this.uiTextBox卷数.Text = 总卷数.ToString(); 
                this.uiTextBox投入重量合计.Text = Math.Round(总投入重量,3).ToString();
                this.uiTextBox产出重量合计.Text = Math.Round(总产出重量,3).ToString();
            }
        }

        private void uiButton修改保存_Click(object sender, EventArgs e)
        {

        }

        private void uiDataGridView产出_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >=0)
            {
                DataGridViewRow dgbr = this.uiDataGridView产出.Rows[e.RowIndex];

              
                string 规格 = dgbr.Cells["C新规格"].Value.ToString();
                string 厚度;

                    string 宽度;
                string 虚拟值;
                pub.FromSize(规格, out 厚度, out 宽度, out 虚拟值);
                string 报工日期= dgbr.Cells["C报工日期"].Value.ToString();
                
                string 填报人 = dgbr.Cells["C填报人"].Value.ToString();
                string 酸洗产出卷号 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C新卷号"].Value.ToString();
                decimal 重量 = pub.Todecimal(dgbr.Cells["C新重量"].Value.ToString());
                string 材质 = dgbr.Cells["C新材质"].Value.ToString();
                string 质量等级 = dgbr.Cells["C质量等级"].Value.ToString();
                string 去向 = dgbr.Cells["C去向"].Value.ToString();
                string 客户 = dgbr.Cells["C客户"].Value.ToString();
                string 质量信息 = dgbr.Cells["C质量信息"].Value.ToString(); 
                 string 存货编号 = dgbr.Cells["C存货编号"].Value.ToString();
                 string 品名 = dgbr.Cells["C品名"].Value.ToString();
                string 后续状态 = pub.Get酸洗产出卷的后续状态(酸洗产出卷号);
                if (后续状态 != "未使用")
                {
                    MessageBox.Show("这个卷状态:" + 后续状态, "提示", MessageBoxButtons.OK);
                    //显示卷信息到表格上
                    // this.uiDataGridView产出.Rows[e.RowIndex].Cells["C后续状态"].Value = 后续状态;
                    ListOutput(this.uiTextBox原料卷号.Text);
                    return;
                }
                else
                {   //本人才能删除
                   
                    if (填报人 != pub.sys_user.UserTrueName&&pub.sys_user.UserTrueName!="超级管理员")
                    {
                        MessageBox.Show("您不可以修改其他人员填报的数据", "提示", MessageBoxButtons.OK);
                        return;
                    }
                    if (MessageBox.Show("你要修改这个产出卷么？数据需要填正确哦！", "询问", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        string sql = "update Bus_PicklingOutput set  " +
                            "OutputDate='"+ 报工日期 +  "'," +
                            "OutputSize='" + 规格 + "'," +
                            "OutputThick='"+ 厚度 + "'," +
                            "OutputWidth='"+ 宽度 + "'," +
                            "OutputQualityGrade='"+ 质量等级 + "'," +
                            "OutputMaterial='"+ 材质 + "'," +
                            "OutputNext='" + 去向 + "'," +
                            "OutputWeight='" + 重量 + "'," +
                            "Customer='" + 客户 + "'," +
                            "OutputQualityInformation='" + 质量信息 + "'," +
                            "InventoryCode='" + 存货编号 + "'," +
                            "InventoryName='" + 品名 + "'" +
                            "where OutputVolumeNew='" + 酸洗产出卷号 + "'";
                       if ( pub.ExecuteSql(pub.ConnectionString, sql, "修改产出的酸洗卷")>0)
                        {
                            MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK);
                        }
                        else
                        {
                            MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK);
                        }
                    }

                }

            }
        }
    }
}
